<template>
  <div>
    <!-- data:  表格的数据 -->
    <!-- row-key: 选择表格元素 -->
    <!-- default-expand-all: 默认展开所有子集 -->
    <!-- tree-props: 树形数据的配置项 -->
    <el-table
      :data="msg.roleList"
      style="width: 100%; margin-bottom: 20px"
      row-key="id"
      border
      stripe
      :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
    >
    <!-- sortable: 排序 -->
      <el-table-column prop="id" label="ID" sortable  width="auto" align='center'>
      </el-table-column>

      <el-table-column prop="rolename" label="角色名称" width="auto" align='center'> </el-table-column>
  
      <el-table-column prop="status" label="状态" width="auto" align='center'>
         <template slot-scope="scope">
          <el-tag v-if="scope.row.status == 1" type="success">已启用</el-tag>
           <el-tag v-else type="danger">未启用</el-tag>
        </template>
      </el-table-column>
    
      <el-table-column label="操作" width="250" align='center'>
        <template slot-scope="scope">
        <el-button
          class="btn2"
          icon='el-icon-edit'
          type='success'
          @click="edit(scope.row)"></el-button>
        <el-button
          type="warning"
          icon='el-icon-view'
          class="btn2"
          cirle
          @click="del(scope.row.id)"></el-button>
        <el-button
          type="danger"
          icon='el-icon-delete'
          class="btn2"
          cirle
          @click="del(scope.row.id)"></el-button>
      </template>
      </el-table-column>
    </el-table>

  
  </div>
</template>

<script>
// 引入

import {delRoleListApi} from '../../api';

export default {
  props:['msg'],
  data() {
    return {
      tableData:[]
    };
  },
  methods: {
    del(id) {
      this.$confirm("此操作将永久删除该内容, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => { // 点击确认按钮
          this.delItem(id);
        })
        .catch(() => {
          this.$message({ // 点击取消按钮
            type: "info",
            message: "已取消删除",
          });
        });
    },
    // 删除
    async delItem(id) {
      // 请求删除接口(api)
      let res = await delRoleListApi(id);
      console.log(res);
      if(res.code == 200){
        // 200 表示删除操作成功
        this.$message({
          type: "success",
          message: "删除成功!",
        });
        console.log(res);
        this.$emit('update');
      }else{
        this.$message({
          type: "warning",
          message: res.msg,
        });
      }
    },
    edit(info){
      // 将数据传给父组件
      console.log('编辑');
      this.$emit('edit',info)
    }

  },
};
</script>

<style>
.el-button.btn2 {
  padding: 0;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  margin-right: 5px;
}
.green {
  color: green;
}
</style>